package com.anhry.app.safety.manage.djpd.struts.action;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.anhry.app.safety.manage.djpd.bean.TbDjpdApply;
import com.anhry.app.safety.manage.djpd.bean.TbDjpdApplyItem;
import com.anhry.app.safety.manage.djpd.bean.TbDjpdApplyView;
import com.anhry.app.safety.manage.djpd.bean.TbDjpdApplyWs1;
import com.anhry.app.safety.manage.djpd.bean.TbDjpdApplyWs2;
import com.anhry.app.safety.manage.djpd.bean.TbDjpdCheck;
import com.anhry.app.safety.manage.djpd.bean.TbDjpdHyBzh;
import com.anhry.app.safety.manage.djpd.bean.TbDjpdHyCheck;
import com.anhry.app.safety.manage.djpd.struts.base.DjpdBaseAction;
import com.anhry.app.safety.manage.enterprise.bean.TbCorpInfo;
import com.anhry.app.safety.manage.enterprise.bean.TbCorpType;
import com.anhry.app.safety.manage.system.bean.TbUser;
import com.anhry.app.safety.manage.system.bean.TbUserDept;
import com.anhry.app.safety.util.Constants;
import com.anhry.app.safety.util.DateFormater;
import com.anhry.app.safety.util.Loggers;
import com.anhry.app.safety.util.Page;
import com.anhry.app.safety.util.Util;
import com.opensymphony.xwork2.ActionContext;

/**
 * @date:2012-11-9
 * @remark:
 * @author:dongbin
 */

@Controller
@Scope("prototype")
@SuppressWarnings("unchecked")
public class DjpdAction extends DjpdBaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private TbDjpdApplyView apply;
	private TbDjpdApplyWs1 ws1;
	private TbDjpdApplyWs2 ws2;
	private TbDjpdCheck check;
	private List itemList;
	private String[] itemIds;
	private String[] itemChecks;
	private String[] sdScore;
	private String[] sdKfMsg;
	private String[] sdHg;
	private String[] sdBhg;
	private String[] hyHg;
	private String[] hyBhg;
	private String[] checkMsg;
	private String[] sdBsj;
	private String isSubmit;
	private String sdDate;//属地评级时间
	private String sdPer1;//属地评级人员
	private String sdPer1Tel;//联系方式
	private String sdPer2;//
	private String sdPer2Tel;//
	private String sdBack;//属地打回
	private String sdBackUser;//属地打回人
	private String hyDate;
	private String hyPer1;//行业复核人员
	private String hyPer1Tel;//联系方式
	private String hyPer2;//
	private String hyPer2Tel;//
	private String ysPer;
	private String ysMsg;
	private String ysTel;
	private String ysDate;
	private String corpId;
	private TbCorpInfo corp;
	private String maxTypeId;//
	private String minTypeId;//
	private String psdwName;//中介机构名称
	private String psdwPer;//确认人
	private String psdwTel;
	private String checkResult;
	private Integer checkRole; //抽查角色 1：县（市，区）安办 2：市安办
	
	

	/**
	 * 县(市、区)、开发区行业审核列表
	 * @return
	 */
	public String countryList(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		if(null!=this.getSearch() && "1".equals(this.getSearch())){num = 1;size = 10;}
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String orderHql = "order by t.zpDate desc";//排序hql语句
			String hql = this.getQuaryHql(1);
			List objSize = this.utilService.getObjecList("TbDjpdApplyView", hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setObjList(this.utilService.getObjecList("TbDjpdApplyView", hql,orderHql,page.getStartRow(),page.getSize()));
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("sd_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:list()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 等级评定查看
	 * @return
	 */
	public String fjpdShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					StringBuilder hql = new StringBuilder("from TbDjpdApplyItem t where 1=1 and t.applyId="+app.getId());
					if(null!=this.cType && this.cType.length()>0){
						hql.append(" and t.zpIsCheck="+this.cType);
					}
					hql.append(" order by t.id");
					this.setItemList((List)this.utilService.getHqlQuery(hql.toString()));
					this.setResult("djpd_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:djpdShow()异常："+e.getMessage());
		}
		return ERROR;
	}
	/**
	 * 等级评定属地初审结果查看
	 * @return
	 */
	public String fjpdSdShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					StringBuilder hql = new StringBuilder("from TbDjpdApplyItem t where 1=1 and t.applyId="+app.getId());
					if(null!=this.cType && this.cType.length()>0){
						hql.append(" and t.sdIsCheck="+this.cType);
					}
					if(null!=this.cType1 && this.cType1.length()>0){
						hql.append(" and t.zpIsCheck="+this.cType1);
					}
					hql.append(" order by t.id");
					this.setItemList((List)this.utilService.getHqlQuery(hql.toString()));
					this.setResult("djpd_sd_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:djpdShow()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 申请书和自评/评估报告
	 * @return
	 */
	public String fjpdWsShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					if("1".equals(this.cType)){
						TbDjpdApplyWs1 ws1 = this.djpdService.getDjpdWs1(this.objId);
						if(null!=ws1){
							this.setWs1(ws1);
						}
						this.setResult("djpd_ws1_show");
						return SUCCESS;
					}
					if("2".equals(this.cType)){
						TbDjpdApplyWs2 ws2 = this.djpdService.getDjpdWs2(this.objId);
						if(null!=ws2){
							this.setWs2(ws2);
						}
						this.setResult("djpd_ws2_show");
						return SUCCESS;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction djpdWsShow() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 属地初审
	 * @return
	 */
	public String sdAudit(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					StringBuilder hql = new StringBuilder("from TbDjpdApplyItem t where 1=1 and t.applyId="+app.getId()+" order by t.id");
					this.setItemList((List)this.utilService.getHqlQuery(hql.toString()));
					this.setResult("djpd_sd_audit");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:sdAudit()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 县(市、区)、开发区行业打回
	 * @return
	 */
	public String sdBack(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					this.setResult("djpd_sd_back");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:sdBack()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 县(市、区)、开发区行业打回保存
	 * @return
	 */
	public String sdBackSave(){
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply app = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=app){
					app.setApplyStatus("5");
					app.setSdBack(sdBack);
					app.setSdBackUser(sdBackUser);
					app.setSdBackDate(new Date());
					this.utilService.update(app);
					this.setTip("操作成功！");
					this.utilService.saveActionLog(user, "将自评id为“"+app.getId()+"”的信息打回企业！");
					return this.sdBack();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:sdBackSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 县(市、区)、开发区行业初审保存
	 * @return
	 */
	public String sdAuditSave(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=obj){
					if("3".equals(this.isSubmit)){
						obj.setApplyStatus("6");
					}else if("1".equals(this.isSubmit)){//同意属地意见
						this.utilService.deleteBySql("update tb_djpd_apply_item t set t.sd_is_check=t.zp_is_check,t.sd_score=t.zp_score,t.sd_kf_msg=t.zp_kf_msg where t.apply_id="+this.objId);
						this.setTip("操作成功！");
						return this.sdAudit();
					}
					if(null!=this.sdHg && this.sdHg.length>0){
						obj.setSdHgNum(this.sdHg.length);
					}else{
						obj.setSdHgNum(0);
					}
					if(null!=this.sdBhg && this.sdBhg.length>0){
						obj.setSdBhgNum(this.sdBhg.length);
					}else{
						obj.setSdBhgNum(0);
					}
					if(null!=this.sdBsj && this.sdBsj.length>0){
						obj.setSdBsjNum(this.sdBsj.length);
					}else{
						obj.setSdBsjNum(0);
					}
					obj.setSdPer1(sdPer1);
					obj.setSdPer1Tel(sdPer1Tel);
					obj.setSdPer2(sdPer2);
					obj.setSdPer2Tel(sdPer2Tel);
					if(null!=this.sdDate && this.sdDate.length()>0){
						obj.setSdDate(DateFormater.formatDate(this.sdDate));
					}else{
						obj.setSdDate(new Date());
					}
					if(null!=this.itemIds && this.itemIds.length>0){
						for(int i=0;i<this.itemIds.length;i++){
							TbDjpdApplyItem item = (TbDjpdApplyItem)this.utilService.getObjectById(TbDjpdApplyItem.class, Long.parseLong(this.itemIds[i]));
							item.setSdIsCheck(this.itemChecks[i]);
							item.setSdKfMsg(this.sdKfMsg[i]);
							if(null!=this.sdScore[i] && this.sdScore[i].length()>0){
								item.setSdScore(Integer.parseInt(this.sdScore[i]));
							}else{
								item.setSdScore(null);
							}
							this.utilService.update(item);
						}
					}
					if("3".equals(this.isSubmit)){
						String sumsql = "select sum(case when t.sd_is_check=3 then 0 when t.sd_is_check=2 and t.sd_score is null then 0 when t.sd_is_check is null then 0 else t.sd_score end) " +
								"from tb_djpd_apply_item t where t.apply_id="+obj.getId();//总分
						String bsjsql = "select sum(t.item_score) from tb_djpd_apply_item t where t.sd_is_check=3 and t.apply_id="+obj.getId();//不涉及项分数
						String jchsql = "select sum(case when t.sd_is_check=3 then 0 when t.sd_is_check=2 and t.sd_score is null then 0 when " +
								"t.sd_is_check is null then 0 else t.sd_score end) from tb_djpd_apply_item t where t.item_type1=1 and t.apply_id="+obj.getId();//基础
						String xchsql = "select sum(case when t.sd_is_check=3 then 0 when t.sd_is_check=2 and t.sd_score is null then 0 when " +
								"t.sd_is_check is null then 0 else t.sd_score end) from tb_djpd_apply_item t where t.item_type1=2 and t.apply_id="+obj.getId();//现场
						obj.setSdJchScore(Integer.parseInt(this.utilService.getObjectBySql(jchsql)));
						obj.setSdJchScore(Integer.parseInt(this.utilService.getObjectBySql(xchsql)));
						Double df = Double.valueOf(Integer.parseInt(this.utilService.getObjectBySql(sumsql))*1000/Double.valueOf(1000-Integer.parseInt(this.utilService.getObjectBySql(bsjsql)))) ;
						DecimalFormat dft = new DecimalFormat("0") ;
						String tem = dft.format(df);
						int score = Integer.parseInt(tem);
						obj.setSdScore(score);
						String gradeDj = "";
						if(score>=900){gradeDj = "A";}
						if(score>=700 && score<900){gradeDj = "B";}
						if(score>=600 && score<700){gradeDj = "C";}
						if(score<600){gradeDj = "D";}
						obj.setSdGrade(gradeDj);
					}
					this.utilService.update(obj);
					this.setTip("操作成功");
					if("2".equals(this.isSubmit)){
						return this.sdAudit();
					}
					return this.countryList();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction sdAuditSave() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 县(市、区)、开发区行业复核
	 * @return
	 */
	public String hyList(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		if(null!=this.getSearch() && "1".equals(this.getSearch())){num = 1;size = 10;}
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String orderHql = "order by t.zpDate desc";//排序hql语句
			String hql = this.getQuaryHql(2);
			List objSize = this.utilService.getObjecList("TbDjpdApplyView", hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setObjList(this.utilService.getObjecList("TbDjpdApplyView", hql,orderHql,page.getStartRow(),page.getSize()));
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("djpd_hy_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:list()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 行业复核页面
	 * @return
	 */
	public String hyAudit(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					List list = (List)this.utilService.getHqlQuery("from TbDjpdHyCheck t where 1=1 and t.applyId="+app.getId()+" order by t.id");
					if(null!=list && list.size()>0){
						this.setObjList(list);
					}else{
						this.initHyCheck(app);
						List list2 = (List)this.utilService.getHqlQuery("from TbDjpdHyCheck t where 1=1 and t.applyId="+app.getId()+" order by t.id");
						this.setObjList(list2);
					}
					this.setResult("djpd_hy_audit");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:hyAudit()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 行业复核成功页面
	 * @return
	 */
	public String hySuccess(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					List list = (List)this.utilService.getHqlQuery("from TbDjpdHyCheck t where 1=1 and t.applyId="+app.getId()+" order by t.id");
					if(null!=list && list.size()>0){
						this.setObjList(list);
					}
					this.setResult("djpd_hy_success");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:hySuccess()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 复核确认查看
	 * @return
	 */
	public String fjpdHyShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					List list = (List)this.utilService.getHqlQuery("from TbDjpdHyCheck t where 1=1 and t.applyId="+app.getId()+" order by t.id");
					if(null!=list && list.size()>0){
						this.setObjList(list);
					}
					this.setResult("djpd_hy_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:djpdHyShow()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 中介结构确认信息
	 * @return
	 */
	public String fjpdPsdwShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					this.setResult("djpd_psdw_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:djpdPsdwShow()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 行业审核
	 * @return
	 */
	public String hyAuditSave(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, obj.getCorpId());
				
				if(null!=obj){
//					if("2".equals(this.isSubmit)){
//						obj.setApplyStatus("7");
//					}
					if(null!=this.hyDate && this.hyDate.length()>0){
						obj.setHyDate(DateFormater.formatDate(this.hyDate));
					}else{
						obj.setHyDate(new Date());
					}
					obj.setHyPer1(hyPer1);
					obj.setHyPer1Tel(hyPer1Tel);
					obj.setHyPer2(hyPer2);
					obj.setHyPer2Tel(hyPer2Tel);
					if(null!=this.itemIds && this.itemIds.length>0){
						for(int i=0;i<this.itemIds.length;i++){
							TbDjpdHyCheck item = (TbDjpdHyCheck)this.utilService.getObjectById(TbDjpdHyCheck.class, Long.parseLong(this.itemIds[i]));
							item.setCheckAudit(this.itemChecks[i]);
							item.setCheckMsg(checkMsg[i]);
							this.utilService.update(item);
						}
					}
					if("2".equals(this.isSubmit)){
						String sql1 = "select count(*) from tb_djpd_hy_check t where t.parent_id=1 and t.check_audit=2 and t.apply_id="+obj.getId();//否决项
						String sql2 = "select count(*) from tb_djpd_hy_check t where t.parent_id=2 and t.check_audit=2 and t.apply_id="+obj.getId();//降级项
						int tem1 = Integer.parseInt(this.utilService.getObjectBySql(sql1));
						int tem2 = Integer.parseInt(this.utilService.getObjectBySql(sql2));
						//int tem3 = Integer.parseInt(this.utilService.getObjectBySql(sql3));
						String gradeDj = "";
						if(tem1>0 || tem2>2){//有否决项或2项以上降级项的直接定为D级
							gradeDj = "D";
						}else if(tem2>0){//有降级项的下浮一个级别。
								if("A".equals(obj.getSdGrade())){gradeDj="B";}
								if("B".equals(obj.getSdGrade())){gradeDj="C";}
								if("C".equals(obj.getSdGrade())){gradeDj="D";}
								if("D".equals(obj.getSdGrade())){gradeDj="D";}
						}else{
							if(Constants.CITY_SUPERVISION.equals(corp.getCorpLixu())) {
								gradeDj=obj.getZpGrade();
							} else {
								gradeDj=obj.getSdGrade();
							}
							
						}
						obj.setHyBzh1(tem1);
						obj.setHyBzh2(tem2);
						obj.setApplyGrade(gradeDj);
					}
					this.utilService.update(obj);
					this.setTip("操作成功");
					if("1".equals(this.isSubmit)){
						return this.hyAudit();
					}
					return this.hySuccess();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction hyAuditSave() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 复核提交
	 * @return
	 */
	public String hySuccSave(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, obj.getCorpId());
				if(null!=obj){
					obj.setApplyStatus("7");
					this.utilService.update(obj);
					corp.setCorpGrade(obj.getApplyGrade());//修改企业的级别
					this.utilService.update(corp);
					this.setTip("复核成功");
					return this.hyList();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction hySuccSave() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 行业移送页面
	 * @return
	 */
	public String hyBack(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					this.setResult("djpd_hy_back");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:hyBack()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	
	/**
	 * 行业移送保存
	 * @return
	 */
	public String hyBackSave(){
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply app = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=app){
					app.setApplyStatus("8");
					app.setYsDate1(new Date());
					app.setYsPer1(ysPer);
					app.setYsMsg1(ysMsg);
					app.setYsTel1(ysTel);
					app.setHyDate(null);
					app.setHyPer1("");
					app.setHyPer1Tel("");
					app.setHyPer2("");
					app.setHyPer2Tel("");
					this.utilService.update(app);
					this.utilService.deleteBySql("delete tb_djpd_hy_check t where 1=1 and t.apply_id="+app.getId());
					this.setTip("操作成功！");
					this.utilService.saveActionLog(user, "将自评id为“"+app.getId()+"”的信息移送给县区安委办了！");
					//
					return this.hyBack();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:sdBackSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 初始化行业复核结果
	 * @param app
	 */
	public void initHyCheck(TbDjpdApplyView app){
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			List list = (List)this.utilService.getHqlQuery("from TbDjpdHyBzh t order by t.parentId,t.id");
			if(null!=app && null!=list && list.size()>0){
				for(int i=0;i<list.size();i++){
					TbDjpdHyBzh bzh = (TbDjpdHyBzh)list.get(i);
					TbDjpdHyCheck obj = new TbDjpdHyCheck();
					obj.setApplyId(app.getId());
					obj.setBzhId(bzh.getId());
					obj.setBzhName(bzh.getBzhName());
					obj.setIsDele("0");
					obj.setParentId(bzh.getParentId());
					obj.setParentName(bzh.getParentName());
					obj.setUserId(user.getId());
					this.utilService.save(obj);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:initHyCheck()异常："+e.getMessage());
		}
	}
	
	/**
	 * 县(市、区)、开发区安委办列表
	 * @return
	 */
	public String qabList(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		if(null!=this.getSearch() && "1".equals(this.getSearch())){num = 1;size = 10;}
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String orderHql = "order by t.zpDate desc";//排序hql语句
			String hql = this.getQuaryHql(3);
			List objSize = this.utilService.getObjecList("TbDjpdApplyView", hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setObjList(this.utilService.getObjecList("TbDjpdApplyView", hql,orderHql,page.getStartRow(),page.getSize()));
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("djpd_qab_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:list()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 县(市、区)、开发区安委办将信息打回行业重新复核页面
	 * @return
	 */
	public String qabBack(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					this.setResult("djpd_qab_back");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:qabBack()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	
	/**
	 * 县(市、区)、开发区安委办将信息打回行业重新复核保存
	 * @return
	 */
	public String qabBackSave(){
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply app = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				if(null!=app){
					app.setApplyStatus("9");
					app.setYsDate2(new Date());
					app.setYsPer2(ysPer);
					app.setYsMsg2(ysMsg);
					app.setYsTel2(ysTel);
					this.utilService.update(app);
					this.utilService.deleteBySql("delete tb_djpd_hy_check t where 1=1 and t.apply_id="+app.getId());
					this.setTip("操作成功！");
					this.utilService.saveActionLog(user, "将自评id为“"+app.getId()+"”的信息重新打回行业进行复核确认了！");
					return this.qabBack();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:qabBackSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 企业类型列表
	 * @return
	 */
	public String typeList(){
		try {
			if(null!=this.corpId && this.corpId.length()>0){
				TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, Long.parseLong(this.corpId));
				if(null!=corp){
					this.setCorp(corp);
					this.setTypeList((List)this.contextPvd.getServletContextAttr(Util.MAX_CORP_TYPE));
					this.setResult("corp_typelist");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("enterprise: CorpConfigAction:corpTypeList() 异常："+e.getMessage());
		}
		this.setTip(Util.NOTIP);
		return ERROR;
	}
	
	/**
	 * 设置企业类型
	 * @return
	 */
	public String corpTypeSet(){
		try {
			TbCorpType maxType = null;
			TbCorpType minType = null;
			if(null!=this.getMaxTypeId() && this.getMaxTypeId().length()>0){
				maxType = (TbCorpType)this.utilService.getObjectById(TbCorpType.class, Long.parseLong(this.getMaxTypeId()));
			}
			if(null!=this.getMinTypeId() && this.getMinTypeId().length()>0){
				minType = (TbCorpType)this.utilService.getObjectById(TbCorpType.class, Long.parseLong(this.getMinTypeId()));
			}
			if(null!=this.corpId && this.corpId.length()>0){
				TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, Long.parseLong(this.corpId));
				if(null!=corp){
					corp.setTbCorpType(maxType);//企业类型大类
					corp.setTbCorpTypeMin(minType);//企业类型小类
					corp.setCorpGrade("");
					corp.setDjpdFpDate(null);
					corp.setDjpdId(null);
					corp.setDjpdNum(0);
					this.utilService.update(corp);
					this.utilService.deleteBySql("delete tb_djpd_apply t where t.corp_Id="+this.corpId);
					this.utilService.deleteBySql("delete tb_djpd_apply_item t where t.corp_Id="+this.corpId);
					this.setTip("修改成功！");
					return this.typeList();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("enterprise: CorpConfigAction:corpTypeSet() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 安委办直接确认页面
	 * @return
	 */
	public String qabAudit(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					List list = (List)this.utilService.getHqlQuery("from TbDjpdHyCheck t where 1=1 and t.applyId="+app.getId()+" order by t.id");
					if(null!=list && list.size()>0){
						this.setObjList(list);
					}else{
						this.initHyCheck(app);
						List list2 = (List)this.utilService.getHqlQuery("from TbDjpdHyCheck t where 1=1 and t.applyId="+app.getId()+" order by t.id");
						this.setObjList(list2);
					}
					this.setResult("djpd_qab_audit");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:qabAudit()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 安委办确认
	 * @return
	 */
	public String qabAuditSave(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply obj = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, obj.getCorpId());
				if(null!=obj){
					if("2".equals(this.isSubmit)){
						obj.setApplyStatus("10");
					}
					if(null!=this.hyDate && this.hyDate.length()>0){
						obj.setHyDate(DateFormater.formatDate(this.hyDate));
					}else{
						obj.setHyDate(new Date());
					}
					obj.setHyPer1(hyPer1);
					obj.setHyPer1Tel(hyPer1Tel);
					obj.setHyPer2(hyPer2);
					obj.setHyPer2Tel(hyPer2Tel);
					if(null!=this.itemIds && this.itemIds.length>0){
						for(int i=0;i<this.itemIds.length;i++){
							TbDjpdHyCheck item = (TbDjpdHyCheck)this.utilService.getObjectById(TbDjpdHyCheck.class, Long.parseLong(this.itemIds[i]));
							item.setCheckAudit(this.itemChecks[i]);
							item.setCheckMsg(checkMsg[i]);
							this.utilService.update(item);
						}
					}
					if("2".equals(this.isSubmit)){
						String sql1 = "select count(*) from tb_djpd_hy_check t where t.parent_id=1 and t.check_audit=2 and t.apply_id="+obj.getId();//红色
						String sql2 = "select count(*) from tb_djpd_hy_check t where t.parent_id=2 and t.check_audit=2 and t.apply_id="+obj.getId();//橙色
						String sql3 = "select count(*) from tb_djpd_hy_check t where t.parent_id=3 and t.check_audit=2 and t.apply_id="+obj.getId();//黄色
						int tem1 = Integer.parseInt(this.utilService.getObjectBySql(sql1));
						int tem2 = Integer.parseInt(this.utilService.getObjectBySql(sql2));
						int tem3 = Integer.parseInt(this.utilService.getObjectBySql(sql3));
						String gradeDj = "";
						if(tem1>0 || tem2>1){//有红色警示项或2项以上橙色项的直接定为D级
							gradeDj = "D";
						}else if(tem2==1 || tem3>2){//有一项橙色警示项或3项以上黄色警示项的定为C级
							gradeDj = "C";
						}else if(tem3>0 && tem3<3){//有1-2项黄色警示项的下浮一个级别
							if("5305".equals(corp.getTbCounty().getId().toString()) || "5306".equals(corp.getTbCounty().getId().toString())){
								if("A".equals(obj.getZpGrade())){gradeDj="B";}
								if("B".equals(obj.getZpGrade())){gradeDj="C";}
								if("C".equals(obj.getZpGrade())){gradeDj="D";}
								if("D".equals(obj.getZpGrade())){gradeDj="D";}
							}else{
								if("A".equals(obj.getSdGrade())){gradeDj="B";}
								if("B".equals(obj.getSdGrade())){gradeDj="C";}
								if("C".equals(obj.getSdGrade())){gradeDj="D";}
								if("D".equals(obj.getSdGrade())){gradeDj="D";}
							}
						}else{
							if("5305".equals(corp.getTbCounty().getId().toString()) || "5306".equals(corp.getTbCounty().getId().toString())){
								gradeDj=obj.getZpGrade();
							}else{
								gradeDj=obj.getSdGrade();
							}
						}
						obj.setApplyGrade(gradeDj);
						corp.setCorpGrade(gradeDj);//修改企业的级别
						this.utilService.update(corp);
					}
					this.utilService.update(obj);
					this.setTip("操作成功");
					if("1".equals(this.isSubmit)){
						return this.qabAudit();
					}
					return this.qabList();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("DjpdAction qabAuditSave() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 已评级列表
	 * @return
	 */
	public String list(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		if(null!=this.getSearch() && "1".equals(this.getSearch())){num = 1;size = 10;}
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			if(user!=null){
				if(user.getTbUserRole()!=null){
				  if(7==user.getTbUserRole().getId()){
					this.setCheckRole(1);
				  }else if(5==user.getTbUserRole().getId()){
				    this.setCheckRole(2);
				  }
			   }  
			}
			String orderHql = "order by t.zpDate desc";//排序hql语句
			String hql = this.getQuaryHql(4);
			List objSize = this.utilService.getObjecList("TbDjpdApplyView", hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setObjList(this.utilService.getObjecList("TbDjpdApplyView", hql,orderHql,page.getStartRow(),page.getSize()));
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("djpd_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:list()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 评审单位确认
	 * @return
	 */
	public String psdwList(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		if(null!=this.getSearch() && "1".equals(this.getSearch())){num = 1;size = 10;}
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String orderHql = "order by t.zpDate desc";//排序hql语句
			String hql = this.getQuaryHql(4);
			List objSize = this.utilService.getObjecList("TbDjpdApplyView", hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setObjList(this.utilService.getObjecList("TbDjpdApplyView", hql,orderHql,page.getStartRow(),page.getSize()));
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("psdw_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:psdwList()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 历史评级记录
	 * @return
	 */
	public String hisList(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		if(null!=this.getSearch() && "1".equals(this.getSearch())){num = 1;size = 10;}
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String orderHql = " order by t.countyId,t.unitId,t.deptId,t.id";//排序hql语句
			String hql = this.getQuaryHql(5);
			List objSize = this.utilService.getObjecList("TbCorpInfoView", hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setObjList(this.utilService.getObjecList("TbCorpInfoView", hql,orderHql,page.getStartRow(),page.getSize()));
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("his_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:hisList()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	public String hisDjList(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbCorpInfo corp = (TbCorpInfo)this.utilService.getObjectById(TbCorpInfo.class, Long.parseLong(this.objId));
				if(null!=corp){
					this.setCorp(corp);
					this.setObjList((List)this.utilService.getHqlQuery("from TbDjpdApplyView t where 1=1 and t.corpId="+this.objId+" and t.applyStatus in (7,10)  order by t.zpDate desc"));
					this.setResult("his_dj_list");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:hisList()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 抽查记录添加页面
	 * @return
	 */
	public String addCheck(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					this.setResult("djpd_check");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:psdwAudit()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	public String checkLook(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdCheck app = (TbDjpdCheck)this.utilService.getObjectById(TbDjpdCheck.class, Long.parseLong(this.objId));
				if(null!=app){
					ActionContext.getContext().put("check", app);
					this.setResult("check_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:psdwAudit()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	
	/**
	 * 分级抽查记录保存
	 * @return
	 */
	public String checkSave(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApply app = (TbDjpdApply)this.utilService.getObjectById(TbDjpdApply.class, Long.parseLong(this.objId));
				TbDjpdCheck check = new TbDjpdCheck();
				check.setApplyId(Long.parseLong(objId));
				check.setPhone(sdPer1Tel);
				check.setCheckPerson(psdwPer);
				check.setSaveDate(new Date());
				check.setCheckResult(checkResult);
				TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
				if(null!=this.hyDate && this.hyDate.length()>0){
					check.setCheckDate(DateFormater.formatDate(this.hyDate));
				}
				if(user!=null){
				  if(7==user.getTbUserRole().getId()){
					check.setCheckDept("1");
				  }else if(5==user.getTbUserRole().getId()){
					check.setCheckDept("2");
				  }
				}
				this.utilService.save(check);
				if(user!=null){
					  if(5==user.getTbUserRole().getId()){
					    app.setPswdId(check.getId());
					    int appchecks = app.getApplyChecks()== null ? 0 :app.getApplyChecks();
					    app.setApplyChecks(appchecks + 1);
					  }else if(7==user.getTbUserRole().getId()){
						app.setQabId(check.getId());
						int appchecks1 = app.getApplyChecks1()== null ? 0 :app.getApplyChecks1(); 
						app.setApplyChecks1(appchecks1 + 1);
					  }
				}
				this.utilService.update(app);
				tip = "添加抽查记录成功！";
				return addCheck();
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:psdwAuditSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/*新增
	 * 何桂芳
	 * 抽查结果查看
	 */
	public String fjpdCheckShow(){
		try {
			if(null!=this.objId && this.objId.length()>0){
				TbDjpdApplyView app = (TbDjpdApplyView)this.utilService.getObjectById(TbDjpdApplyView.class, Long.parseLong(this.objId));
				if(null!=app){
					this.setApply(app);
					StringBuilder hql = new StringBuilder("from TbDjpdCheck t where 1=1 and t.applyId="+app.getId());
					hql.append(" and t.checkDept= '"+cType);
					hql.append("' order by t.id");
					List list = (List)this.utilService.getHqlQuery(hql.toString());
					if(list==null || list.size()==0){
						this.setCheck(null);
					}else{
					    this.setCheck((TbDjpdCheck)list.get(0));
					}
					this.setResult("djpd_check_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("djpd: DjpdBzhAction:fjpdCheckShow()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	public String getQuaryHql(int type){
		TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
		String grade = user.getTbUserGrade().getId().toString();//用户级别
		TbUserDept unit = null;//用户单位
		TbUserDept dept = null;//用户部门
		if(null!=user.getTbUserUnit()){
			unit = user.getTbUserUnit();
		}
		if(null!=user.getTbUserDept()){
			dept = user.getTbUserDept();
		}
		StringBuilder urls = new StringBuilder("");
		StringBuilder hql = new StringBuilder(" where 1=1 ");
		String key = "";
		if(null!=this.keyWord && this.keyWord.length()>0){
			if(null!=this.getSearch() && "1".equals(this.getSearch())){
				key = this.getKeyWord().trim();
			}else{
				key = this.contextPvd.decode(this.getKeyWord());	
			}
			this.setKeyWord(key);
			hql.append(" and t.corpName like '%"+key+"%'");
			urls.append("keyWord="+this.contextPvd.encode(this.keyWord));
		}else{
			urls.append("keyWord=");
		}
		
		if("3".equals(grade) && "3".equals(dept.getDeptClass())){//市科室行业部门
			hql.append(" and t.deptMainId="+dept.getId());
			urls.append("&cHy="+dept.getId().toString());
			this.setCHy(dept.getId().toString());
			if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}
		}else if("4".equals(grade) && "3".equals(dept.getDeptClass())){//县区科室行业部门
			if((null==this.cMaxType || "".equals(this.cMaxType)) && (null==this.cMinType || "".equals(this.cMinType))){
				hql.append(" and t.quDeptIds like '%"+dept.getId()+"%'");
			}else{
				if(null!=this.cMaxType && this.cMaxType.length()>0){
					hql.append(" and t.maxTypeId="+this.cMaxType);
					urls.append("&cMaxType="+this.cMaxType);
				}
				if(null!=this.cMinType && this.cMinType.length()>0){
					hql.append(" and t.minTypeId="+this.cMinType);
					urls.append("&cMinType="+this.cMinType);
				}
			}
			if(null!=this.cHy && this.cHy.length()>0){
				hql.append(" and t.deptMainId="+this.cHy);
				urls.append("&cHy="+this.cHy);
			}
		}else if("5".equals(grade)){//市行业
			if("1".equals(unit.getDeptClass())){//行业监管
				hql.append(" and t.deptMainId="+unit.getId());
				urls.append("&cHy="+unit.getId().toString());
				this.setCHy(unit.getId().toString());
			}else{//专业监管
				if("5310".equals(unit.getId().toString())){//质监局
					hql.append(" and t.corpIsTeshe=1");
				}else if("5311".equals(unit.getId().toString())){//消防局
					
				}else if("5312".equals(unit.getId().toString())){//气象局
					hql.append(" and t.corpIsBlzh=1");
				}
				if(null!=this.cHy && this.cHy.length()>0){
					hql.append(" and t.deptMainId="+this.cHy);
					urls.append("&cHy="+this.cHy);
				}
			}
			if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}
		}else if("6".equals(grade)){//区行业
			if("1".equals(dept.getDeptClass())){
				hql.append(" and t.deptMainId="+dept.getDeptSj());
				urls.append("&cHy="+dept.getDeptSj().toString());
				this.setCHy(dept.getDeptSj().toString());
			}else{
				if("5310".equals(dept.getDeptSj().toString())){//质监局
					hql.append(" and t.corpIsTeshe=1");
				}else if("5311".equals(dept.getDeptSj().toString())){//消防局
					
				}else if("5312".equals(dept.getDeptSj().toString())){//气象局
					hql.append(" and t.corpIsBlzh=1");
				}
				if(null!=this.cHy && this.cHy.length()>0){
					hql.append(" and t.deptMainId="+this.cHy);
					urls.append("&cHy="+this.cHy);
				}
			}
			if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}
		}else{//其他用户
			if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}
			if(null!=this.cHy && this.cHy.length()>0){
				hql.append(" and t.deptMainId="+this.cHy);
				urls.append("&cHy="+this.cHy);
			}
		}
		
		if("4".equals(grade) || "6".equals(grade) || "8".equals(grade)){//县区安委会、区科室、区行业
			hql.append(" and t.countyId="+unit.getId());
			this.setCCounty(unit.getId().toString());
			if(null!=this.cUnit && this.cUnit.length()>0){
				hql.append(" and t.unitId="+this.cUnit);
				urls.append("&cUnit="+this.cUnit);
			}
			if(null!=this.cDept && this.cDept.length()>0){
				hql.append(" and t.deptId="+this.cDept);
				urls.append("&cDept="+this.cDept);
			}
		}else if("7".equals(grade)){//属地
			hql.append(" and t.countyId="+unit.getId()+" and t.unitId="+dept.getId());
			this.setCCounty(unit.getId().toString());
			this.setCUnit(dept.getId().toString());
			if(null!=this.cDept && this.cDept.length()>0){
				hql.append(" and t.deptId="+this.cDept);
				urls.append("&cDept="+this.cDept);
			}
		}else{
			if(null!=this.cCounty && this.cCounty.length()>0){
				hql.append(" and t.countyId="+this.cCounty);
				urls.append("&cCounty="+this.cCounty);
			}
			if(null!=this.cUnit && this.cUnit.length()>0){
				hql.append(" and t.unitId="+this.cUnit);
				urls.append("&cUnit="+this.cUnit);
			}
			if(null!=this.cDept && this.cDept.length()>0){
				hql.append(" and t.deptId="+this.cDept);
				urls.append("&cDept="+this.cDept);
			}
		}
		if(null!=this.cZcType && this.cZcType.length()>0){
			hql.append(" and t.corpReportType="+this.cZcType);
			urls.append("&cZcType="+this.cZcType);
		}
		if(null!=this.cGrade && this.cGrade.length()>0){
			if("E".equals(this.cGrade)){
				hql.append(" and t.corpGrade is null");
			}else{
				hql.append(" and t.corpGrade='"+this.cGrade+"'");
			}
			urls.append("&cGrade="+this.cGrade);
		}
		if(type==1){//乡镇初审
			if(null!=this.cAudit && this.cAudit.length()>0){
				hql.append(" and t.applyStatus="+this.cAudit);
				urls.append("&cAudit="+this.cAudit);
			}
		}
		if(type==2){//县区行业初复核
			if(null!=this.cAudit && this.cAudit.length()>0){
				hql.append(" and t.applyStatus="+this.cAudit);
				urls.append("&cAudit="+this.cAudit);
			}
			hql.append(" and t.applyStatus>5");
		}
		if(type==3){//县区行业初复核
			if(null!=this.cAudit && this.cAudit.length()>0){
				hql.append(" and t.applyStatus="+this.cAudit);
				urls.append("&cAudit="+this.cAudit);
			}
			hql.append(" and t.applyStatus>7");
		}
		if(type==4){//已评级记录
			if(null!=this.cAudit && this.cAudit.length()>0){
				hql.append(" and t.applyStatus="+this.cAudit);
				urls.append("&cAudit="+this.cAudit);
			}else{
				hql.append(" and t.applyStatus in (7,10)");
			}
		}
		if(type==5){//已评级记录
			hql.append(" and t.corpGrade is not null");
		}
		this.setUrls(urls.toString());
		return hql.toString();
	}

	public TbDjpdApplyView getApply() {
		return apply;
	}

	public void setApply(TbDjpdApplyView apply) {
		this.apply = apply;
	}

	public TbDjpdApplyWs1 getWs1() {
		return ws1;
	}

	public void setWs1(TbDjpdApplyWs1 ws1) {
		this.ws1 = ws1;
	}

	public TbDjpdApplyWs2 getWs2() {
		return ws2;
	}

	public void setWs2(TbDjpdApplyWs2 ws2) {
		this.ws2 = ws2;
	}

	public List getItemList() {
		return itemList;
	}

	public void setItemList(List itemList) {
		this.itemList = itemList;
	}

	public String getIsSubmit() {
		return isSubmit;
	}

	public void setIsSubmit(String isSubmit) {
		this.isSubmit = isSubmit;
	}

	public String[] getItemChecks() {
		return itemChecks;
	}

	public void setItemChecks(String[] itemChecks) {
		this.itemChecks = itemChecks;
	}

	public String[] getItemIds() {
		return itemIds;
	}

	public void setItemIds(String[] itemIds) {
		this.itemIds = itemIds;
	}

	public String[] getSdBhg() {
		return sdBhg;
	}

	public void setSdBhg(String[] sdBhg) {
		this.sdBhg = sdBhg;
	}

	public String[] getSdBsj() {
		return sdBsj;
	}

	public void setSdBsj(String[] sdBsj) {
		this.sdBsj = sdBsj;
	}

	public String[] getSdHg() {
		return sdHg;
	}

	public void setSdHg(String[] sdHg) {
		this.sdHg = sdHg;
	}

	public String[] getSdKfMsg() {
		return sdKfMsg;
	}

	public void setSdKfMsg(String[] sdKfMsg) {
		this.sdKfMsg = sdKfMsg;
	}

	public String[] getSdScore() {
		return sdScore;
	}

	public void setSdScore(String[] sdScore) {
		this.sdScore = sdScore;
	}

	public String getSdBack() {
		return sdBack;
	}

	public void setSdBack(String sdBack) {
		this.sdBack = sdBack;
	}

	public String getSdBackUser() {
		return sdBackUser;
	}

	public void setSdBackUser(String sdBackUser) {
		this.sdBackUser = sdBackUser;
	}

	public String getSdDate() {
		return sdDate;
	}

	public void setSdDate(String sdDate) {
		this.sdDate = sdDate;
	}

	public String getSdPer1() {
		return sdPer1;
	}

	public void setSdPer1(String sdPer1) {
		this.sdPer1 = sdPer1;
	}

	public String getSdPer1Tel() {
		return sdPer1Tel;
	}

	public void setSdPer1Tel(String sdPer1Tel) {
		this.sdPer1Tel = sdPer1Tel;
	}

	public String getSdPer2() {
		return sdPer2;
	}

	public void setSdPer2(String sdPer2) {
		this.sdPer2 = sdPer2;
	}

	public String getSdPer2Tel() {
		return sdPer2Tel;
	}

	public void setSdPer2Tel(String sdPer2Tel) {
		this.sdPer2Tel = sdPer2Tel;
	}


	public String getHyDate() {
		return hyDate;
	}

	public void setHyDate(String hyDate) {
		this.hyDate = hyDate;
	}

	public String getHyPer1() {
		return hyPer1;
	}

	public void setHyPer1(String hyPer1) {
		this.hyPer1 = hyPer1;
	}

	public String getHyPer1Tel() {
		return hyPer1Tel;
	}

	public void setHyPer1Tel(String hyPer1Tel) {
		this.hyPer1Tel = hyPer1Tel;
	}

	public String getHyPer2() {
		return hyPer2;
	}

	public void setHyPer2(String hyPer2) {
		this.hyPer2 = hyPer2;
	}

	public String getHyPer2Tel() {
		return hyPer2Tel;
	}

	public void setHyPer2Tel(String hyPer2Tel) {
		this.hyPer2Tel = hyPer2Tel;
	}

	public String[] getHyBhg() {
		return hyBhg;
	}

	public void setHyBhg(String[] hyBhg) {
		this.hyBhg = hyBhg;
	}

	public String[] getHyHg() {
		return hyHg;
	}

	public void setHyHg(String[] hyHg) {
		this.hyHg = hyHg;
	}

	public String[] getCheckMsg() {
		return checkMsg;
	}

	public void setCheckMsg(String[] checkMsg) {
		this.checkMsg = checkMsg;
	}

	public String getYsDate() {
		return ysDate;
	}

	public void setYsDate(String ysDate) {
		this.ysDate = ysDate;
	}

	public String getYsPer() {
		return ysPer;
	}

	public void setYsPer(String ysPer) {
		this.ysPer = ysPer;
	}

	public String getYsTel() {
		return ysTel;
	}

	public void setYsTel(String ysTel) {
		this.ysTel = ysTel;
	}

	public String getYsMsg() {
		return ysMsg;
	}

	public void setYsMsg(String ysMsg) {
		this.ysMsg = ysMsg;
	}

	public String getCorpId() {
		return corpId;
	}

	public void setCorpId(String corpId) {
		this.corpId = corpId;
	}

	public TbCorpInfo getCorp() {
		return corp;
	}

	public void setCorp(TbCorpInfo corp) {
		this.corp = corp;
	}

	public String getMaxTypeId() {
		return maxTypeId;
	}

	public void setMaxTypeId(String maxTypeId) {
		this.maxTypeId = maxTypeId;
	}

	public String getMinTypeId() {
		return minTypeId;
	}

	public void setMinTypeId(String minTypeId) {
		this.minTypeId = minTypeId;
	}

	public String getPsdwName() {
		return psdwName;
	}

	public void setPsdwName(String psdwName) {
		this.psdwName = psdwName;
	}

	public String getPsdwPer() {
		return psdwPer;
	}

	public void setPsdwPer(String psdwPer) {
		this.psdwPer = psdwPer;
	}

	public String getPsdwTel() {
		return psdwTel;
	}

	public void setPsdwTel(String psdwTel) {
		this.psdwTel = psdwTel;
	}

	public String getCheckResult() {
		return checkResult;
	}

	public void setCheckResult(String checkResult) {
		this.checkResult = checkResult;
	}

	public TbDjpdCheck getCheck() {
		return check;
	}

	public void setCheck(TbDjpdCheck check) {
		this.check = check;
	}
	public Integer getCheckRole() {
		return checkRole;
	}

	public void setCheckRole(Integer checkRole) {
		this.checkRole = checkRole;
	}

}
